﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;

namespace QLHS2010
{
    public class LopDAO : DataProvider
    {
        public LopDAO()
        {
            connect();
        }

        //public ArrayList getDsLop()
        //{
        //    connect();
        //    string query = "SELECT * FROM Lop";
        //    adapter = new OleDbDataAdapter(query, connection);
        //    DataSet dataset = new DataSet();
        //    adapter.Fill(dataset);
        //    ArrayList arr = ConvertDataSetToArrayList(dataset);

        //    return arr;
        //}

        public LopDTO[] getDsLop()
        {
            string query = "SELECT * FROM Lop";
            adapter = new OleDbDataAdapter(query, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            LopDTO[] arr;

            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            arr = new LopDTO[n];
            for (i = 0; i < n; i++)
            {
                object lop = GetDataFromDataRow(dt, i);
                arr[i] = (LopDTO)lop;
            }
            return arr;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            LopDTO lop = new LopDTO();
            lop.TenLop = dt.Rows[i]["TenLop"].ToString();
            lop.SiSo = int.Parse(dt.Rows[i]["SiSo"].ToString());
            lop.Khoi = dt.Rows[i]["Khoi"].ToString();
            return (object)lop;
        }
    }
}
